package com.bitcola.security.activity.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;

import java.math.BigDecimal;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicInteger;

@Data
@Builder
@AllArgsConstructor
public class UserNet {
    String userId;
    String tel;
    String email;
    String inviter;
    String kyc;
    @JsonIgnore
    List<UserNet>child;
    @JsonIgnore
    List<UserMining>userMinings;
    volatile BigDecimal selfPower=BigDecimal.ZERO;//自身算力



    AtomicInteger directNum;
    volatile BigDecimal childrensPower=BigDecimal.ZERO;//直推算力
    volatile BigDecimal groupPower=BigDecimal.ZERO;//团队算力
    AtomicInteger groupKyc;//团队kyc
    AtomicInteger groupNum;//团队人数
    AtomicInteger directMiningNum;//直推挖矿人数
    AtomicInteger groupMiningNum;//团队挖矿人数
    AtomicInteger directKyc;//直推kyc
     volatile BigDecimal gained;

     public void addGroupKyc(int num)
     {
         groupKyc.addAndGet(num);
     }
     public void addGroupNum(int num)
     {
         groupNum.addAndGet(num);

     }
     public void addDirectMiningNum(int num){
         directMiningNum.addAndGet(num);
     }
     public void addGroupMiningNum(int num){
         groupMiningNum.addAndGet(num);
     }

     public void addDirectKyc(int num)
     {
         directKyc.addAndGet(num);
     }
     public void addGained(BigDecimal num){
         synchronized (this){
             gained=gained.add(num);
         }

     }

     public void addSelfPower(BigDecimal num){
         synchronized (this) {
             selfPower = selfPower.add(num);
         }

     }

     public void addDirectPower(BigDecimal num){
         synchronized (this) {
             childrensPower = childrensPower.add(num);
         }
     }
     public void addGroupPower(BigDecimal num){
         synchronized (this){
             groupPower=groupPower.add(num);
         }

     }

     public void addDirectNum(int num)
     {
         directNum.addAndGet(num);
     }
     public void  init()
    {
         selfPower=BigDecimal.ZERO;//自身算力

        gained=BigDecimal.ZERO;
        childrensPower=BigDecimal.ZERO;
        groupPower=BigDecimal.ZERO;
        child=new CopyOnWriteArrayList<>();
        userMinings=new CopyOnWriteArrayList<>();
        directKyc=new AtomicInteger(0);
        groupMiningNum=new AtomicInteger(0);
        directMiningNum=new AtomicInteger(0);
        groupNum=new AtomicInteger(0);
        groupKyc=new AtomicInteger(0);
        directNum=new AtomicInteger(0);
    }
    public UserNet(){
        child=new CopyOnWriteArrayList<>();
        userMinings=new CopyOnWriteArrayList<>();
        selfPower=BigDecimal.ZERO;//自身算力

        gained=BigDecimal.ZERO;
        childrensPower=BigDecimal.ZERO;
        groupPower=BigDecimal.ZERO;
        child=new CopyOnWriteArrayList<>();
        userMinings=new CopyOnWriteArrayList<>();
        directKyc=new AtomicInteger(0);
        groupMiningNum=new AtomicInteger(0);
        directMiningNum=new AtomicInteger(0);
        groupNum=new AtomicInteger(0);
        groupKyc=new AtomicInteger(0);
        directNum=new AtomicInteger(0);
    }




}
